using System;
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
using dnAnalytics.Math;
using dnAnalytics.LinearAlgebra;
using dnAnalytics.Exceptions;

namespace dnAnalytics.UnitTests.LinearAlgebra
{
    public class JaggedMatrix : Matrix
    {
        private double[][] data;

        public JaggedMatrix(int rows, int columns): base(rows, columns)
        {
            data = new double[rows][];
            for (int i = 0; i < rows; i++)
            {
                data[i] = new double[columns];
            }
        }

        protected override Matrix CreateMatrix(int rows, int columns)
        {
            return new JaggedMatrix(rows, columns);
        }

        protected internal override double ValueAt(int row, int column)
        {
            return data[row][column];
        }

        protected internal override void ValueAt(int row, int column, double value)
        {
            data[row][column] = value;
        }
    }


    [TestFixture]
    [Category("Managed")]
    public class UserDefinedMatrixTest : AbstractMatrixTest
    {
        public override Matrix GetMatrix(int order)
        {
            return new JaggedMatrix(order, order);
        }

        public override Matrix GetMatrix(int m, int n)
        {
            return new JaggedMatrix(m, n);
        }

        public override Matrix GetMatrix(double[,] data)
        {
            int rows = data.GetLength(0);
            int cols = data.GetLength(1);
            Matrix ret = new JaggedMatrix(rows, cols);
            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < cols; j++)
                {
                    ret[i, j] = data[i, j];
                }
            }

            return ret;
        }

        public override Vector GetVector(int size)
        {
            return VectorBuilder.CreateVector(size, VectorType.Dense);
        }

        public override Vector GetVector(double[] source)
        {
            return VectorBuilder.CreateVector(source, VectorType.Dense);
        }
    }
}
